<?php

namespace app\api\controller;

use think\Db;

class Online
{
    public function index(){

        $url = 'http://10.20.10.44:801/eportal/admin/online';
        $content = file_get_contents($url);
        $data = json_decode($content,true);
        Db::table('tbl_onlinelist')->insertAll($data,true);
        Db::table('tbl_online_fx')->insert(['nums'=>count($data)]);
        echo date('Y-m-d H:i:s');
        if (date('H:i')=='23:55'){
            $this->history();
        }
    }

    private function history(){
        $sql = 'insert into tbl_onlinelist_history select * from tbl_onlinelist';
        sleep(1);
        echo Db::execute($sql);
        Db::execute('delete from tbl_onlinelist');
    }

}